package com.bzxy.monitor.action;

import java.io.IOException;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;


//import org.apache.struts2.ServletActionContext;

import com.bzxy.monitor.model.User;
import com.bzxy.monitor.service.UserManageService;
import com.bzxy.monitor.serviceImpl.LoginServiceImpl;
import com.bzxy.monitor.serviceImpl.UserManageServiceImpl;
import com.opensymphony.xwork2.ActionSupport;
import com.bzxy.monitor.until.Constants;;


public class LoginAction extends ActionSupport implements SessionAware{
	private static final long serialVersionUID = 1L;
	private User user;
	private String errortip;
	private LoginServiceImpl loginSrv = new LoginServiceImpl();
	private Map<String, Object> userSession;
	
	public String valide() throws IOException{
		System.out.println("[LoginAction::valide]:user:" + user.getUsername() + "psw:" + user.getPassword());
		errortip = loginSrv.valide(user);
		//ServletActionContext.getResponse().setCharacterEncoding("UTF-8"); 		
		
		if ( errortip == Constants.SUC_VALIDE_PASS ){
			UserManageService userSvr = new UserManageServiceImpl();
			User userInfo = userSvr.Find(user.getUsername());
			userSession.put("LoginName", userInfo.getShowname());			
			return LOGIN;
		}
		else{
			return ERROR;	
		}		
	}
	
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}	
	
	public String getErrortip() {
		return errortip;
	}

	public void setErrortip(String errortip) {
		this.errortip = errortip;
	}

	public LoginServiceImpl getLoginSrv() {
		return loginSrv;
	}

	public void setLoginSrv(LoginServiceImpl loginSrv) {
		this.loginSrv = loginSrv;
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		userSession = arg0;
	}
}
